﻿
using Newtonsoft.Json;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Models.Common;
using Models.JsonResultModel;
using ServiceWeb.DBGateway;
using Models.Constant;
using ServiceWeb.WebAdmin;
using UtilsBase;
using UtilsORM;
using UtilsORM.MySqlData;
using UtilsORM.MySqlData;
using UtilsORM.MySqlData;
using GatewayServer.Common;

namespace GatewayServer.Controllers
{
    public class ProductServerController : BaseMagerController
    {
        EFYihongIotContext ef = new EFYihongIotContext();

        EFYihongIotContext eFIotBase = new EFYihongIotContext();
        public IActionResult list(IFormCollection FC, HttpReqModel httpRequest, int PageIndex = 1, int PageSize = 15)
        {
            List<SugarParameter> sugarParameters = new List<SugarParameter>();
            int totalRecord = 0;
            string sqlwhere = "  ";
            if (!string.IsNullOrEmpty(httpRequest.pGuid))
            {
                sqlwhere = sqlwhere + " and sp_product_guid=@pGuid ";
                sugarParameters.Add(new SugarParameter("pGuid", httpRequest.pGuid));

            }
            if (!string.IsNullOrEmpty(FC["hid_pageIndex"]))
            {
                PageIndex = int.Parse(FC["hid_pageIndex"].ToString());

            }

            if (!string.IsNullOrEmpty(httpRequest.code))
            {
                sqlwhere = sqlwhere + " and s_code=@s_code ";
                sugarParameters.Add(new SugarParameter("s_code", httpRequest.code.Trim()));

            }

            string sql = "select  * from rm_server_system_product inner join rm_server_system on sp_s_guid=s_guid left join rm_client on sp_c_guid=c_guid  where 1= 1  " + sqlwhere;
            DataTable dt = MySqlYihongIot.getPageDataTable(PageIndex, PageSize, sql, sugarParameters, "sp_id desc", ref totalRecord);

            ViewData["DataList"] = dt;

            ViewBag.PageSize = PageSize;
            ViewBag.RecordCount = totalRecord;//总条数
            ViewBag.PageCount = totalRecord % PageSize == 0 ? totalRecord / PageSize : totalRecord / PageSize + 1;//分的页数
            ViewBag.PageIndex = PageIndex;//当前页码
            return View(httpRequest);
        }

    }
}